const { Service } = require('egg');

class OfficialBeerService extends Service {
  async list() {
    const sql = `SELECT
* 
FROM
user_beer_wall
LEFT JOIN official_beer ON user_beer_wall.offcial_beer_id = official_beer.id`;

    const results = await this.app.mysql.query(sql);

    return results;
  }

  async detail(where) {
    const results = await this.app.mysql.select('user_beer_wall', {
      where,
    });

    return results?.[0] || null;
  }

  async add(data) {
    const results = await this.app.mysql.insert('user_beer_wall', data);

    return results;
  }
}

module.exports = OfficialBeerService;
